package com.ptszyxx.popose.module.main.trip;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.constants.BundleConstant;
import com.ptszyxx.popose.databinding.FragmentTripBinding;
import com.ptszyxx.popose.databinding.FragmentTripDetailBinding;
import com.ptszyxx.popose.module.main.trip.vm.TripDetailVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.http.data.entity.dynamic.DynamicResult;
import com.ysg.utils.YStringUtil;

import java.util.ArrayList;
import java.util.List;

public class TripDetailFragment extends BaseFragment<FragmentTripDetailBinding, TripDetailVM> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_trip_detail;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public TripDetailVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(TripDetailVM.class);
    }

    @Override
    public void initParam() {
        super.initParam();
        Bundle bundle = getArguments();
        if (bundle != null){
            viewModel.entity.set(bundle.getParcelable(BundleConstant.ENTITY));
        }
    }

    @Override
    public void initData() {
        super.initData();

        if (viewModel.entity.get() != null){
            DynamicResult result = new DynamicResult();
            if (YStringUtil.isNotEmpty(viewModel.entity.get().getMedia())){
                result.setImageList(YStringUtil.getListByComma(viewModel.entity.get().getMedia()));
            }else{
                List<String> list = new ArrayList<>();
                list.add(viewModel.entity.get().getUserImg());
                result.setImageList(list);
            }
            binding.dynamicImage.setData(result);
        }
    }
}
